| Conditions | 1 |
| Paths | 16 |
| Total Lines | 443 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 96 | initialize: function () { |
||
| 97 | |||
| 98 | var self = this; |
||
| 99 | |||
| 100 | navdiv.initElements(); |
||
| 101 | navdiv.initUI(); |
||
| 102 | |||
| 103 | // |
||
| 104 | // /** |
||
| 105 | // * |
||
| 106 | // * @constructor |
||
| 107 | // */ |
||
| 108 | // this.UIReset = function () { |
||
| 109 | // navdiv.newTypeDefinition.children('div').fadeOut(0); |
||
| 110 | // $('#circles_new_type_' + |
||
| 111 | // navdiv.newType.children('option:selected').val()).fadeIn( 0); |
||
| 112 | // navdiv.newType.hide(); navdiv.newSubmit.hide(); navdiv.newTypeDefinition.hide(); |
||
| 113 | // $('.icon-circles').css('background-image', 'url(' + OC.imagePath('circles', |
||
| 114 | // 'colored') + ')'); navdiv.membersSearchResult.hide(); }; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * |
||
| 118 | */ |
||
| 119 | this.initTweaks = function () { |
||
| 120 | $.fn.emptyTable = function () { |
||
| 121 | this.children('tr').each(function () { |
||
| 122 | if ($(this).attr('class') != 'header') { |
||
| 123 | $(this).remove(); |
||
| 124 | } |
||
| 125 | }); |
||
| 126 | }; |
||
| 127 | |||
| 128 | |||
| 129 | }; |
||
| 130 | |||
| 131 | |||
| 132 | // |
||
| 133 | // this.displayMembersInteraction = function (details) { |
||
| 134 | // if (details.user.level < 6) { |
||
| 135 | // divAddMember.hide(); |
||
| 136 | // } else { |
||
| 137 | // divAddMember.show(); |
||
| 138 | // } |
||
| 139 | // |
||
| 140 | // this.displayNonMemberInteraction(details); |
||
| 141 | // |
||
| 142 | // if (details.user.level == 9) { |
||
| 143 | // navdiv.joinCircle.hide(); |
||
| 144 | // navdiv.leaveCircle.hide(); |
||
| 145 | // return; |
||
| 146 | // } |
||
| 147 | // |
||
| 148 | // if (details.user.level >= 1) { |
||
| 149 | // navdiv.joinCircle.hide(); |
||
| 150 | // navdiv.leaveCircle.show(); |
||
| 151 | // } |
||
| 152 | // |
||
| 153 | // }; |
||
| 154 | |||
| 155 | |||
| 156 | this.displayNonMemberInteraction = function (details) { |
||
| 157 | navdiv.joinCircleAccept.hide(); |
||
| 158 | navdiv.joinCircleReject.hide(); |
||
| 159 | navdiv.joinCircleRequest.hide(); |
||
| 160 | navdiv.joinCircleInvite.hide(); |
||
| 161 | |||
| 162 | if (details.user.status == 'Invited') { |
||
| 163 | navdiv.joinCircleInvite.show(); |
||
| 164 | navdiv.joinCircleAccept.show(); |
||
| 165 | navdiv.joinCircleReject.show(); |
||
| 166 | navdiv.joinCircle.hide(); |
||
| 167 | navdiv.leaveCircle.hide(); |
||
| 168 | return; |
||
| 169 | } |
||
| 170 | |||
| 171 | if (details.user.status == 'Requesting') { |
||
| 172 | navdiv.joinCircleRequest.show(); |
||
| 173 | navdiv.joinCircle.hide(); |
||
| 174 | navdiv.leaveCircle.show(); |
||
| 175 | return; |
||
| 176 | } |
||
| 177 | |||
| 178 | navdiv.joinCircle.show(); |
||
| 179 | navdiv.leaveCircle.hide(); |
||
| 180 | }; |
||
| 181 | |||
| 182 | |||
| 183 | // /** |
||
| 184 | // * |
||
| 185 | // */ |
||
| 186 | // this.initAnimationNewCircle = function () { |
||
| 187 | // |
||
| 188 | // navdiv.newName.on('keyup', function () { |
||
| 189 | // self.onEventNewCircleName(); |
||
| 190 | // }); |
||
| 191 | // |
||
| 192 | // navdiv.newType.on('change', function () { |
||
| 193 | // self.onEventNewCircleType(); |
||
| 194 | // }); |
||
| 195 | // |
||
| 196 | // navdiv.newSubmit.on('click', function () { |
||
| 197 | // api.createCircle(navdiv.newType.val(), navdiv.newName.val(), |
||
| 198 | // self.createCircleResult); |
||
| 199 | // }); |
||
| 200 | // |
||
| 201 | // }; |
||
| 202 | |||
| 203 | |||
| 204 | /** |
||
| 205 | * |
||
| 206 | * @param display |
||
| 207 | */ |
||
| 208 | this.displayOptionsNewCircle = function (display) { |
||
| 209 | if (display) { |
||
| 210 | navdiv.newType.fadeIn(300); |
||
| 211 | navdiv.newSubmit.fadeIn(500); |
||
| 212 | navdiv.newTypeDefinition.fadeIn(700); |
||
| 213 | } |
||
| 214 | else { |
||
| 215 | navdiv.newType.fadeOut(700); |
||
| 216 | navdiv.newSubmit.fadeOut(500); |
||
| 217 | navdiv.newTypeDefinition.fadeOut(300); |
||
| 218 | } |
||
| 219 | }; |
||
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * |
||
| 224 | */ |
||
| 225 | this.initExperienceCirclesList = function () { |
||
| 226 | |||
| 227 | navdiv.circlesList.children('div').on('click', function () { |
||
| 228 | self.displayCirclesList($(this).attr('circle-type')); |
||
| 229 | }); |
||
| 230 | |||
| 231 | $('#circles_search').on('input propertychange paste focus', function () { |
||
| 232 | if (curr.searchCircle == $(this).val().trim()) { |
||
| 233 | return; |
||
| 234 | } |
||
| 235 | |||
| 236 | curr.searchCircle = $(this).val().trim(); |
||
| 237 | api.searchCircles(curr.circlesType, $(this).val().trim(), |
||
| 238 | self.listCirclesResult); |
||
| 239 | }); |
||
| 240 | |||
| 241 | }; |
||
| 242 | |||
| 243 | |||
| 244 | /** |
||
| 245 | * |
||
| 246 | * @param type |
||
| 247 | */ |
||
| 248 | this.displayCirclesList = function (type) { |
||
| 249 | |||
| 250 | curr.circlesType = type; |
||
| 251 | curr.searchCircle = ''; |
||
| 252 | curr.searchUser = ''; |
||
| 253 | |||
| 254 | curr.circle = 0; |
||
| 255 | curr.circleLevel = 0; |
||
| 256 | |||
| 257 | navdiv.navigation.show('slide', 800); |
||
| 258 | navdiv.emptyContent.show(800); |
||
| 259 | navdiv.mainUI.fadeOut(800); |
||
| 260 | |||
| 261 | $('#circles_search').val(''); |
||
| 262 | $('#addmember').val(''); |
||
| 263 | |||
| 264 | this.UIresetCirclesList(type); |
||
| 265 | api.listCircles(type, self.listCirclesResult); |
||
| 266 | }; |
||
| 267 | |||
| 268 | |||
| 269 | /** |
||
| 270 | * |
||
| 271 | * @constructor |
||
| 272 | */ |
||
| 273 | this.UIresetCirclesList = function (type) { |
||
| 274 | |||
| 275 | navdiv.circlesList.children('div').removeClass('selected'); |
||
| 276 | navdiv.circlesList.children().each(function () { |
||
| 277 | if ($(this).attr('circle-type') == type.toLowerCase()) { |
||
| 278 | $(this).addClass('selected'); |
||
| 279 | } |
||
| 280 | }); |
||
| 281 | |||
| 282 | navdiv.navigation.addClass('selected'); |
||
| 283 | navdiv.navigation.children().each(function () { |
||
| 284 | if ($(this).attr('id') != 'circles_search') { |
||
| 285 | $(this).remove(); |
||
| 286 | } |
||
| 287 | }); |
||
| 288 | }; |
||
| 289 | |||
| 290 | |||
| 291 | /** |
||
| 292 | * |
||
| 293 | * @param result |
||
| 294 | */ |
||
| 295 | this.listCirclesResult = function (result) { |
||
| 296 | |||
| 297 | if (result.status < 1) { |
||
| 298 | OCA.notification.onFail( |
||
| 299 | 'Issue while retreiving the list of the Circles: ' + |
||
| 300 | ((result.error) ? result.error : 'no error message')); |
||
| 301 | return; |
||
| 302 | } |
||
| 303 | |||
| 304 | var data = result.data; |
||
| 305 | for (var i = 0; i < data.length; i++) { |
||
| 306 | var tmpl = self.generateTmplCircle(data[i]); |
||
| 307 | navdiv.navigation.append( |
||
| 308 | '<div class="circle" circle-id="' + data[i].id + '">' + tmpl + |
||
| 309 | '</div>'); |
||
| 310 | } |
||
| 311 | |||
| 312 | navdiv.navigation.children('.circle').on('click', function () { |
||
| 313 | self.selectCircle($(this).attr('circle-id')); |
||
| 314 | }); |
||
| 315 | }; |
||
| 316 | |||
| 317 | |||
| 318 | /** |
||
| 319 | * |
||
| 320 | * @returns {*|jQuery} |
||
| 321 | * @param entry |
||
| 322 | */ |
||
| 323 | this.generateTmplCircle = function (entry) { |
||
| 324 | var tmpl = $('#tmpl_circle').html(); |
||
| 325 | |||
| 326 | tmpl = tmpl.replace(/%title%/, entry.name); |
||
| 327 | tmpl = tmpl.replace(/%type%/, entry.type); |
||
| 328 | tmpl = tmpl.replace(/%owner%/, entry.owner.user_id); |
||
| 329 | tmpl = tmpl.replace(/%status%/, entry.user.status); |
||
| 330 | tmpl = tmpl.replace(/%level_string%/, entry.user.level_string); |
||
| 331 | tmpl = tmpl.replace(/%count%/, entry.count); |
||
| 332 | tmpl = tmpl.replace(/%creation%/, entry.creation); |
||
| 333 | |||
| 334 | return tmpl; |
||
| 335 | }; |
||
| 336 | |||
| 337 | // |
||
| 338 | // /** |
||
| 339 | // * |
||
| 340 | // * @param circle_id |
||
| 341 | // */ |
||
| 342 | // this.selectCircle = function (circle_id) { |
||
| 343 | // curr.searchUser = ''; |
||
| 344 | // $('#addmember').val(''); |
||
| 345 | // |
||
| 346 | // api.detailsCircle(circle_id, this.selectCircleResult); |
||
| 347 | // }; |
||
| 348 | // |
||
| 349 | |||
| 350 | this.selectCircleResult = function (result) { |
||
| 351 | |||
| 352 | navdiv.mainUIMembers.emptyTable(); |
||
| 353 | |||
| 354 | if (result.status < 1) { |
||
| 355 | OCA.notification.onFail( |
||
| 356 | 'Issue while retreiving the details of a circle: ' + |
||
| 357 | ((result.error) ? result.error : 'no error message')); |
||
| 358 | return; |
||
| 359 | } |
||
| 360 | |||
| 361 | navdiv.navigation.children('.circle').removeClass('selected'); |
||
| 362 | navdiv.navigation.children(".circle[circle-id='" + result.circle_id + "']").each( |
||
| 363 | function () { |
||
| 364 | $(this).addClass('selected'); |
||
| 365 | }); |
||
| 366 | |||
| 367 | navdiv.emptyContent.hide(800); |
||
| 368 | navdiv.mainUI.fadeIn(800); |
||
| 369 | curr.circle = result.circle_id; |
||
| 370 | curr.circleLevel = result.details.user.level; |
||
| 371 | |||
| 372 | self.displayMembersInteraction(result.details); |
||
| 373 | self.displayMembers(result.details.members); |
||
| 374 | }; |
||
| 375 | |||
| 376 | // |
||
| 377 | // /** |
||
| 378 | // * |
||
| 379 | // * @param search |
||
| 380 | // */ |
||
| 381 | // this.searchMembersRequest = function (search) { |
||
| 382 | // |
||
| 383 | // if (curr.searchUser == search) { |
||
| 384 | // return; |
||
| 385 | // } |
||
| 386 | // |
||
| 387 | // curr.searchUser = search; |
||
| 388 | // |
||
| 389 | // $.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees', |
||
| 390 | // { |
||
| 391 | // format: 'json', |
||
| 392 | // search: search, |
||
| 393 | // perPage: 200, |
||
| 394 | // itemType: 'principals' |
||
| 395 | // }, self.searchMembersResult); |
||
| 396 | // }; |
||
| 397 | // |
||
| 398 | // |
||
| 399 | // this.searchMembersResult = function (response) { |
||
| 400 | // |
||
| 401 | // if (response === null || |
||
| 402 | // (response.ocs.data.users === 0 && response.ocs.data.exact.users === 0)) { |
||
| 403 | // navdiv.membersSearchResult.fadeOut(300); |
||
| 404 | // return; |
||
| 405 | // } |
||
| 406 | // |
||
| 407 | // navdiv.membersSearchResult.children().remove(); |
||
| 408 | // |
||
| 409 | // self.searchMembersResultFill(response.ocs.data.exact.users, |
||
| 410 | // response.ocs.data.users); |
||
| 411 | // |
||
| 412 | // $('.members_search').on('click', function () { |
||
| 413 | // api.addMember(curr.circle, $(this).attr('searchresult'), |
||
| 414 | // self.addMemberResult); |
||
| 415 | // }); |
||
| 416 | // navdiv.membersSearchResult.fadeIn(300); |
||
| 417 | // |
||
| 418 | // }; |
||
| 419 | |||
| 420 | |||
| 421 | // this.searchMembersResultFill = function (exact, partial) { |
||
| 422 | // $.each(exact, function (index, value) { |
||
| 423 | // navdiv.membersSearchResult.append( |
||
| 424 | // '<div class="members_search exact" searchresult="' + |
||
| 425 | // value.value.shareWith + '">' + value.label + ' (' + |
||
| 426 | // value.value.shareWith + ')</div>'); |
||
| 427 | // }); |
||
| 428 | // |
||
| 429 | // $.each(partial, function (index, value) { |
||
| 430 | // var currSearch = $('#addmember').val().trim(); |
||
| 431 | // var line = value.label + ' (' + value.value.shareWith + ')'; |
||
| 432 | // if (currSearch.length > 0) { |
||
| 433 | // line = |
||
| 434 | // line.replace(new RegExp('(' + currSearch + ')', 'gi'), |
||
| 435 | // '<b>$1</b>'); |
||
| 436 | // } |
||
| 437 | // |
||
| 438 | // navdiv.membersSearchResult.append( |
||
| 439 | // '<div class="members_search" searchresult="' + |
||
| 440 | // value.value.shareWith + |
||
| 441 | // '">' + line + '</div>'); |
||
| 442 | // }); |
||
| 443 | // |
||
| 444 | // navdiv.membersSearchResult.children().first().css('border-top-width', '0px'); |
||
| 445 | // }; |
||
| 446 | |||
| 447 | |||
| 448 | // /** |
||
| 449 | // * |
||
| 450 | // * @param result |
||
| 451 | // */ |
||
| 452 | // this.addMemberResult = function (result) { |
||
| 453 | // |
||
| 454 | // if (result.status == 1) { |
||
| 455 | // OCA.notification.onSuccess( |
||
| 456 | // "Member '" + result.name + "' successfully added to the circle"); |
||
| 457 | // |
||
| 458 | // self.displayMembers(result.members); |
||
| 459 | // return; |
||
| 460 | // } |
||
| 461 | // OCA.notification.onFail( |
||
| 462 | // "Member '" + result.name + "' NOT added to the circle: " + |
||
| 463 | // ((result.error) ? result.error : 'no error message')); |
||
| 464 | // }; |
||
| 465 | |||
| 466 | |||
| 467 | this.generateTmplMember = function (entry) { |
||
| 468 | var tmpl = $('#tmpl_member').html(); |
||
| 469 | |||
| 470 | tmpl = tmpl.replace(/%username%/g, entry.user_id); |
||
| 471 | tmpl = tmpl.replace(/%level%/g, entry.level); |
||
| 472 | tmpl = tmpl.replace(/%levelstring%/g, entry.level_string); |
||
| 473 | tmpl = tmpl.replace(/%status%/, entry.status); |
||
| 474 | tmpl = tmpl.replace(/%joined%/, entry.joined); |
||
| 475 | tmpl = tmpl.replace(/%note%/, entry.note); |
||
| 476 | |||
| 477 | return tmpl; |
||
| 478 | }; |
||
| 479 | |||
| 480 | |||
| 481 | |||
| 482 | |||
| 483 | |||
| 484 | this.joinCircleResult = function (result) { |
||
| 485 | if (result.status == 1) { |
||
| 486 | |||
| 487 | navdiv.mainUIMembers.children("[member-id='" + result.name + "']").each( |
||
| 488 | function () { |
||
| 489 | $(this).hide(300); |
||
| 490 | }); |
||
| 491 | |||
| 492 | if (result.member.level == 1) { |
||
| 493 | OCA.notification.onSuccess( |
||
| 494 | "You have successfully joined this circle"); |
||
| 495 | } else { |
||
| 496 | OCA.notification.onSuccess( |
||
| 497 | "You have requested an invitation to join this circle"); |
||
| 498 | } |
||
| 499 | self.selectCircle(result.circle_id); |
||
| 500 | return; |
||
| 501 | } |
||
| 502 | |||
| 503 | OCA.notification.onFail( |
||
| 504 | "Cannot join this circle: " + |
||
| 505 | ((result.error) ? result.error : 'no error message')); |
||
| 506 | |||
| 507 | }; |
||
| 508 | |||
| 509 | this.leaveCircleResult = function (result) { |
||
| 510 | if (result.status == 1) { |
||
| 511 | |||
| 512 | navdiv.mainUIMembers.children("[member-id='" + result.name + "']").each( |
||
| 513 | function () { |
||
| 514 | $(this).hide(300); |
||
| 515 | }); |
||
| 516 | |||
| 517 | self.selectCircle(result.circle_id); |
||
| 518 | OCA.notification.onSuccess( |
||
| 519 | "You have successfully left this circle"); |
||
| 520 | return; |
||
| 521 | } |
||
| 522 | |||
| 523 | OCA.notification.onFail( |
||
| 524 | "Cannot leave this circle: " + |
||
| 525 | ((result.error) ? result.error : 'no error message')); |
||
| 526 | |||
| 527 | }; |
||
| 528 | |||
| 529 | |||
| 530 | /** |
||
| 531 | * Inits |
||
| 532 | */ |
||
| 533 | this.initTweaks(); |
||
| 534 | // this.UIReset(); |
||
| 535 | this.initAnimationNewCircle(); |
||
| 536 | this.initExperienceCirclesList(); |
||
| 537 | // this.initExperienceMembersManagment(); |
||
| 538 | } |
||
| 539 | }; |
||
| 578 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.